package com.future;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;

/**
 * Description:
 * 给定一个会议时间安排的数组 intervals ，每个会议时间都会包括开始和结束的时间 intervals[i] = [starti, endi] ，请你判断一个人是否能够参加这里面的全部会议。
 * <p>
 * 来源：力扣（LeetCode）
 * 链接：https://leetcode-cn.com/problems/meeting-rooms
 * 著作权归领扣网络所有。商业转载请联系官方授权，非商业转载请注明出处。
 *
 * @Author: future
 * @Date:2022/3/3:18:35
 */
public class Solution_canAttendMeetings_252 {

    public static void main(String[] args) {
        // intervals = [[0,30],[5,10],[15,20]];
        int[][] intervals = {{0, 30}, {5, 10}, {15, 20}};
        intervals = new int[][]{{7, 10}, {2, 4}};
        System.out.println(canAttendMeetings(intervals));
        System.out.println();
        test();
    }

    private static void test() {
        int[] arr = new int[]{4, 3, 1, 43, 65, 23, 6};

        List<Integer> list = new ArrayList<>();
       /* list.sort(new Comparator<Integer>() {
            public int compare(Integer o1, Integer o2) {
                return o1 - o2;
            }
        });*/
        for (int i = 0; i < arr.length; i++) {
            list.add(arr[i]);
        }
        list.sort(new Comparator<Integer>() {
            public int compare(Integer o1, Integer o2) {
                return o1 - o2;
            }
        });
        System.out.println(list);
    }

    public static boolean canAttendMeetings(int[][] intervals) {
        List<MyObject> list = new ArrayList<>();

        for (int i = 0; i < intervals.length; i++) {
            list.add(new MyObject(intervals[i][0], intervals[i][1]));
        }
        list.sort(new Comparator<MyObject>() {
            @Override
            public int compare(MyObject o1, MyObject o2) {
                return o1.start - o2.start;
            }
        });
        if (list == null || list.size() == 0) {
            return true;
        }
        int preEnd = 0;
        for (MyObject obj : list) {
            if (preEnd > obj.start) {
                return false;
            }
            preEnd = obj.end;
        }
        return true;
    }
}


class MyObject {
    Integer start;

    Integer end;

    public MyObject() {

    }

    public MyObject(Integer start, Integer end) {
        this.start = start;
        this.end = end;
    }
}